<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>我的地址</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">

    <!--标准mui.css-->
    <link rel="stylesheet" href="__PUBLIC__/css/mui.min.css">
    <!--App自定义的css-->
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/app.css" />
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    <script src="__PUBLIC__/layer_mobile/layer.js"></script>
</head>

<body>
<header class="mui-bar mui-bar-nav">
    <a style="position:absolute;z-index: 2"  class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
    <a href="{:U('indexSet')}" style='position:absolute; z-index:3; width:40px; height:40px; left:0px; top:0px;background: blue;opacity:0'></a>
    <h1 class="mui-title">新增地址</h1>
</header>
<div class="mui-content" id="ul">
    <foreach name="arr" item="v">
        <ul class="my-shouhuo mui-table-view">
            <li><span class="mui-name">{$v.Contact}</span> <span class="mui-phone">{$v.Mobile}</span></li>
            <li>{$v.ProvName}{$v.CityName}{$v.DistName}{$v.Addr}</li>
        </ul>
        <div class="mui-input-row mui-checkbox mui-left mui-mrdz">
            <label class="w50">默认地址</label>
            <?php if($v["Default"]=='TRUE'){?>
                <input _value="<?php echo $v['AddrID'];?>" name="checkbox" value="Item 1" type="checkbox" checked>
                <?php }else{ ?>
                <input _value="<?php echo $v['AddrID'];?>" name="checkbox" value="Item 1" type="checkbox">
            <?php } ?>
            <div class="mui-cz">
                <a href="javascript:;" class="edit" name="{$v.Contact}" tel="{$v.Mobile}"  city_id="{$v.ProvID},{$v.CityID},{$v.DistrictID}" city="{$v.ProvName},{$v.CityName},{$v.DistName}"  city_info="{$v.Addr}" default="{$v.Default}" id="{$v.AddrID}"><div class="fl"><i class="mui-bj"></i><span style="color: #7e7e7e;">编辑</span></div></a>
                <a href="{:U('address_del',array('id'=>$v['AddrID']))}"><div class="fl"><i class="mui-sc"></i><span style="color: #7e7e7e;">删除</span></div></a>
            </div>
        </div>
        <div class="zwbg"></div>
    </foreach>
    <!--占位-->
    <ul class="my-shouhuo mui-table-view"></ul>

    <div class="mui-input-row mui-checkbox mui-left mui-mrdz"></div>

    <div class="foter-btn">
        <button type="button" onclick="location.href='{:U('add_address')}'" class="btnpf mui-btn-sz">添加新地址</button>
    </div>

</div>
<script src="__PUBLIC__/js/mui.min.js"></script>


</body>

</html>
<script>

    var page = 1, //分页码
            off_on = false, //分页开关(滚动加载方法 1 中用的)
            timers = null; //定时器(滚动加载方法 2 中用的)
    //还可以基window窗口（body）来添加滚动事件, (因为布局不同,所以在这里没效果，因为[上面是基于body中的某个元素来添加滚动事的])
    $(window).scroll(function() {
        //当时滚动条离底部60px时开始加载下一页的内容
        if (($(window).height() + $(window).scrollTop() + 120) >= $(document).height()) {
            clearTimeout(timers);
            timers = setTimeout(function() {
                page++;
                //alert(page)
                $.post("{:U('address_list')}",{page:page},function(rels)
                {
                    if(rels.code == '0')
                    {
                        var html="";
                        var data=rels.data;
                        for(var i=0;i<data.length;i++){
                            html+='<ul class="my-shouhuo mui-table-view">'
                            html+='<li><span class="mui-name">'+data[i].Contact+'</span> <span class="mui-phone">'+data[i].Mobile+'</span></li>'
                            html+='<li>'+data[i].ProvName+data[i].CityName+data[i].DistName+data[i].Addr+'</li>'
                            html+='</ul>'
                            html+='<div class="mui-input-row mui-checkbox mui-left mui-mrdz">'
                            html+='<label class="w50">默认地址</label>'
                            if(data[i].Default=='TRUE'){
                                html+='<input _value="'+data[i].AddrID+'" name="checkbox" value="Item 1" type="checkbox" checked>'
                            }else{
                                html+='<input _value="'+data[i].AddrID+'" name="checkbox" value="Item 1" type="checkbox">'
                            }
                            html+='<div class="mui-cz">'
                            html+='<a href="javascript:;" class="edit" name="'+data[i].Contact+'" tel="'+data[i].Mobile+'"  city="'+data[i].ProvName+'","'+data[i].CityName+'","'+data[i].DistName+'" city_id="{$v.ProvID},{$v.CityID},{$v.DistrictID}" city_info="'+data[i].Addr+'" default="'+data[i].Default+'" id="'+data[i].AddrID+'"><div class="fl"><i class="mui-bj"></i><span style="color: #7e7e7e;">编辑</span></div></a>'
                            html+='<a href="/index.php?g=YunCangChu&m=my&a=address_del&id='+data[i].AddrID+'"><div class="fl"><i class="mui-sc"></i><span style="color: #7e7e7e;">删除</span></div></a>'
                            html+='</div></div><div class="zwbg"></div>'
                        }
                        $('#ul').append(html)
                    }
                })
            }, 300);
        }
    });
    $(".edit").click(function(){
        var id=$(this).attr("id");
        var name=$(this).attr("name");
        var tel=$(this).attr("tel");
        var city=$(this).attr("city");
        var city_id=$(this).attr("city_id");
        var city_info=$(this).attr("city_info");
        var defaults=$(this).attr("default");
        window.location.href="/index.php?g=YunCangChu&m=My&a=address_edit&id="+id+"&name="+name+"&tel="+tel+"&city="+city+"&city_info="+city_info+"&defaults="+defaults+"&city_id="+city_id
    })
</script>
<script>
    $(":checkbox").click(function(){
        var id = $(this).attr('_value')
        //切换默认地址
        $.post("{:U('defaults')}",{id:id},function (rels) {
            if(rels == 200)
            {
                location = location
            }
            else
            {
                layer.open({
                    content: '设置失败'
                    ,btn: '我知道了'
                });
                return false
            }
        })
    });
</script>